package cn.itheima;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/StudentDemo")
    public class StudentDemo extends HttpServlet {
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //接收请求 获取表单参数
            String name = request.getParameter("username");
            String age = request.getParameter("age");
            String grade = request.getParameter("grade");
            //写入文本
            BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\a.txt"));
            bw.write(name + age + grade);
            bw.newLine();
            bw.close();

            //反馈浏览器
            //根据方法获取打印流对象
            PrintWriter pw = response.getWriter();
            pw.println("save success");
        }

        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request, response);
        }
    }

